<?php

namespace app\model;

use app\service\RedisService;
use app\stateData;
use think\facade\Db;
use think\Model;
use think\model\concern\SoftDelete;

class OrderEnterpriseExchange extends Model
{

    /**
     * 倒证表
     */
    use SoftDelete;

    protected $createTime = 'create_date';
    protected $deleteTime = 'delete_date';

    const INFO_GENERATE_STATUS_ONE = 1;//信息生成状态 1-未生成
    const INFO_GENERATE_STATUS_TWO = 2;//信息生成状态 2-信息生成
    const INFO_GENERATE_STATUS_THREE = 3;//信息生成状态 3-信息存在

    public function getIds()
    {
        return $this->column ('id');
    }

    public function certificateCode(): \think\model\relation\HasOne
    {
        return $this->hasOne(OrderDeal::class, 'order_id', 'id')->bind([
            'certificate_code' => 'certificate_code',
            'status' => 'order_status',
            'electronic_certificate_file' => 'electronic_certificate_file',
            'electronic_certificate_date' => 'electronic_certificate_date',
            'b_electronic_certificate_file' => 'b_electronic_certificate_file',
            'b_electronic_certificate_date' => 'b_electronic_certificate_date',
            'b_reg_electronic_certificate_date' => 'b_reg_electronic_certificate_date'
        ]);
    }

    public function chargeback()
    {
        return $this->hasOne (OrderDealChargeback::class,'certificate_code','certificate_code')
            ->bind ([
                'order_company_id',
                'chargeback_performance'=>'performance',
                'charge_back_date',
                'reason',
                'get_uid_up_logoff_file',
                'notifier_get_uid',
                'push_uidup_logoff_file',
                'notifier_push_uid',
                'b_certificate_is_conpany',
                'chargeback_create_date'=>'create_date',
                'chargeback_type'=>'type'
            ])->order('create_date DESC');
    }

    public function certificates()
    {
        return $this->hasOne(OrderEnterpriseCertificateRegister::class, 'certificate_code', 'certificate_code')
            ->bind(['sale_org', 'sale_uid', 'reg_unit', 'price_unit', 'certificate_id', 'certificate_b', 'social_security', 'cycle', 'project', 'people_num']);
    }

    public function getEmployUnitTypeAttr($name): array
    {
        if ($name === ''){
            return [
                'id'=>'',
                'text'=>''
            ];
        }

        return [
            'id' => $name,
            'text' => stateData::$_employ_unit_type[$name]
        ];
    }

    public function getOutOrgAttr($name): array
    {
        return [
            'id' => $name?:'',
            'text' => (new UserOrganization())->getStructureName($name) ?: ''
        ];
    }

    public function getOutUidAttr($name): array
    {
        return [
            'id' => $name?:'',
            'text' => (new User())->getIdNickName($name) ?: ''
        ];
    }

    public function getNoticeIdAttr($name): array
    {
        return [
            'id' => $name?:'',
            'text' => (new User())->getIdNickName($name) ?: ''
        ];
    }


    public function getProjectAttr($value): array
    {
        if ($value === ''){
            return [
                'id'=>'',
                'text'=>''
            ];
        }
        return [
            'id' => (int)$value,
            'text' => stateData::$_project[$value]
        ];
    }

    public function getCertificateBAttr($value): array
    {
        if ($value === ''){
            return [
                'id'=>'',
                'text'=>''
            ];
        }
        return [
            'id' => (int)$value,
            'text' => stateData::$_b_doc[$value]
        ];
    }

    public function getSocialSecurityAttr($value): array
    {
        if ($value === ''){
            return [
                'id'=>'',
                'text'=>''
            ];
        }
        return [
            'id' => (int)$value,
            'text' => stateData::$_social_security[$value]
        ];
    }

    public function getCycleAttr($value): array
    {
        if (!$value){
            return [
                'id'=>'',
                'text'=>''
            ];
        }
        return [
            'id'=>(int)$value,
            'text'=>stateData::$_cycle[$value]
        ];

    }

    public function getTransferAttr($value): array
    {

        return [
            'id' => $value?:'',
            'text' => stateData::$_transfer[$value]
        ];
    }

    public function getCertificateCodeAttr($name): string
    {
        return $name ?: '';
    }

    public function getStatusAttr($name)
    {
        return [
            'id' => $name,
            'text' => stateData::$_enter_certificate_reg[$name]
        ];
    }

    public function getInfoGenerateStatusAttr($name)
    {
        return [
            'id' => $name,
            'text' => stateData::$_certificate_dz_info_status[$name]
        ];
    }

    public function getGetUidAttr($name)
    {
        return [
            'id'=>$name?:'',
            'text'=>(new User())->getIdNickName($name)?:''
        ];
    }

    public function getGetOrgAttr($name)
    {
        return [
            'id'=>$name?:'',
            'text'=>(new UserOrganization())->getStructureName($name)?:''
        ];
    }

    public function getNoticeOrgAttr($name)
    {
        return [
            'id'=>$name?:'',
            'text'=>(new UserOrganization())->getStructureName($name)?:''
        ];
    }

    public function getCertificateLeixingAttr($name)
    {
        return [
            'id' => $name,
            'text' => (new SystemCertificate)->getWhereIdCertificateModel($name) ?: ''
        ];
    }

    public function getCertificateLeibieAttr($name)
    {
        return [
            'id' => $name,
            'text' => (new SystemCertificate)->getWhereIdCertificateModel($name) ?: ''
        ];
    }

    public function getCertificateDengjiAttr($name)
    {
        return [
            'id' => $name,
            'text' => (new SystemCertificate)->getWhereIdCertificateModel($name) ?: ''
        ];
    }

    public function getCertificateZhuanyeAttr($name)
    {
        return [
            'id' => $name,
            'text' => (new SystemCertificate)->getWhereIdCertificateModel($name) ?: ''
        ];
    }

    public function getInfoFileNameAttr($name)
    {
        return $name?:'';
    }

    public function getRegFileNameAttr($name)
    {
        return $name?:'';
    }

    public function getOtherFileNameAttr($name)
    {
        return $name?:'';
    }

    public function getSaleDateAttr($name)
    {
        if ($name === '0000-00-00 00:00:00' || empty($name)){
            return "";
        }
//        return date ('Y-m-d',strtotime ($name));
        return $name;
    }

    public function getRegFileAttr($value)
    {
        if (empty($value)) return "";
        $arr = explode(',',$value);
        $value = '';
        foreach($arr as &$v){
            $value .= config('file.url').$v .',';
        }
        return rtrim($value,',');
    }

    public function getInfoFileAttr($value)
    {
        if (empty($value)) return "";
        $arr = explode(',',$value);
        $value = '';
        foreach($arr as &$v){
            $value .= config('file.url').$v .',';
        }
        return rtrim($value,',');
    }

    public function getOtherFileAttr($value)
    {
        if (empty($value)) return "";
        $arr = explode(',',$value);
        $value = '';
        foreach($arr as &$v){
            $value .= config('file.url').$v .',';
        }
        return rtrim($value,',');
    }

    public function getRegBecomeDateAttr($name)
    {
        if ($name === '0000-00-00 00:00:00'){
            return '';
        }
        return $name;
    }
    public function getSfkStatusAttr($name)
    {
        return [
            'id'=>$name?:'',
            'text'=>stateData::$_sfk_status[$name]
        ];
    }

//    public function getOutPriceAttr($name)
//    {
//        if ($name == '0.00'){
//            return '';
//        }
//        return $name;
//    }
//
//    public function getGetPriceAttr($name)
//    {
//        if ($name == '0.00'){
//            return '';
//        }
//        return $name;
//    }
    public function getSfkWcDateAttr($name)
    {
        if (!$name || $name =='0000-00-00 00:00:00') return '';
        return date ('Y-m-d',strtotime ($name));
    }

    public function addDataModel($data)
    {
        return self::create($data);
    }

    public function getDataModel($page, $pageNum)
    {
//        return $this->with ('certificateCode')->page ($page,$pageNum)->select ();
        return $this->page($page, $pageNum)->select();
    }

    public function getDataCountModel(): int
    {
        return $this->count();
    }


    public function getExchangeListIds($idArr)
    {
        if (is_array ($idArr)){
            $idArr = implode ($idArr,',');
        }
//        $list = $this
//            ->whereRaw ('out_uid IN ('.$idArr.') OR notice_id IN ('.$idArr.') OR get_uid IN ('.$idArr.')')
//            ->select()->toArray();
//        return array_column($list, 'id');

        return $this->whereRaw ('out_uid IN ('.$idArr.') OR notice_id IN ('.$idArr.') OR get_uid IN ('.$idArr.')')->column ('id');
    }

    /**
     * 获取倒证列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getExchangeListModel($page, $pageNum, $ids)
    {
        return $this->where('id', 'in', $ids)->order('create_date DESC')->select()->toArray();
    }

    public function getExchangeLIstIdModel($ids)
    {
        return $this->where ('id','in',$ids)->column ('id,certificate_code,sale_date');
    }

    /**
     * 获取用户权限范围ID certificate_code sale_date
     * @param $idArr
     * @return array
     */
    public function getUserRandDataModel($idArr)
    {
        if (is_array($idArr)) {
            $idStr = implode(',',$idArr);
        }
        return $this->whereRaw('notice_id in ('.$idStr.') OR out_uid in ('.$idStr.') OR get_uid  in ('.$idStr.')')->column ('id,certificate_code,sale_date');
        // return $this->whereIn ('notice_id',$idArr)->whereIn ('get_uid',$idArr)->whereIn ('out_uid',$idArr)->column ('id,certificate_code,sale_date');
    }

    public function getExchangeAllListModel($page, $pageNum, $ids)
    {
        return $this->where('id', 'in', $ids)->order('create_date DESC')->select()->toArray();
    }

    public function getExchangeIdCardListModel($idCard)
    {
        return $this->where('id_card', 'in', $idCard)->select()->toArray();
    }

    /**
     * 查询聘用单位|注册单位|出证单位与name相等的数据
     * @param $name
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getEnterpriseOrName($name)
    {
        return $this->whereOR (['employ_unit_title'=>$name])->whereOR (['unit_reg_title'=>$name])->whereOR (['out_unit'=>$name])->select ()->toArray ();
    }


    public function getExchangeCountModel($ids)
    {
        return $this->where('id', 'in', $ids)->count();
    }


    public function getOtherExchangeListIds($id)
    {
//        $list = $this->where(['get_uid' => $id])->whereOr (['notice_id'=>$id])->whereOr (['out_uid'=>$id])->order('create_date DESC')->select()->toArray();
//        $list = $this->order('create_date DESC')->select()->toArray();
//        return array_column($list,'id');
        return $this->order('create_date DESC')->column ('id');
    }

    /**
     * 获取个人提交的倒证列表
     * @param $id
     * @param $page
     * @param $pageNum
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getOtherExchangeListModel($id, $page, $pageNum, $ids)
    {
//        return $this->with ('chargeback')->where(['get_uid' => $id])->whereOr (['notice_id'=>$id])->whereOr (['out_uid'=>$id])->page($page, $pageNum)->where('id', 'in', $ids)->order('create_date DESC')->select()->toArray();
        $data = $this->with (['chargeback'=>function($query) use ($id){
            return $query->getQuery()->where(['notifier_get_uid'=>$id])->whereOr (['notifier_push_uid'=>$id]);
        }])
//        $data = $this->with ('chargeback')
            ->where('id', 'in', $ids)
            ->where (['get_uid'=>$id])
            ->whereOr (['notice_id'=>$id,'out_uid'=>$id,'submit_id'=>$id])
            ->order('create_date DESC')
//            ->fetchSql(true)
            ->select()
            ->toArray ();
        //判断通知人 审批人等是否是当前用户
//        $result = [];
//        foreach ($data as $k => $item) {
//            if ($item['notifier_get_uid'] == $id || $item['notifier_push_uid'] == $id){
//                $result[] = $item;
//            }
//        }

//        return array_values ($result);
        return $data;

    }

    public function getExchangeIdListModel($id,$ids){

        return $this->with (['chargeback'=>function($query) use ($id){
            return $query->getQuery()->where(['notifier_get_uid'=>$id])->whereOr (['notifier_push_uid'=>$id]);
        }])
            ->where('id', 'in', $ids)
//            ->where (['get_uid'=>$id])
//            ->whereOr (['notice_id'=>$id,'out_uid'=>$id,'submit_id'=>$id])
            ->whereRaw ("get_uid=".$id." OR notice_id=".$id." OR out_uid=".$id." OR submit_id=".$id)
            ->order('create_date DESC')
//            ->fetchSql(true)
            ->column ('id,certificate_code,sale_date');
    }

    public function getOtherExchangeCountModel($id,$ids)
    {
        return $this->where(['get_uid' => $id])->whereOr (['notice_id'=>$id])->whereOr (['out_uid'=>$id])->where('id', 'in', $ids)->order('create_date DESC')->count();
    }

    /**
     * 通过证书倒证id修改倒证库
     * @param $data
     * @return \app\model\OrderEnterpriseExchange
     */
    public function editEnterIdDataModel($data)
    {
        return $this->where(['enter_id' => $data['id']])->update($data);
    }

    /**
     * 修改
     * @param $data
     * @return \app\model\OrderEnterpriseExchange
     */
    public function editDataModel($data)
    {
        /**
         * 修改数据也同步更新缓存 保证业绩统计完整性
         */
        //先通过ID查询sale_date
        $saleDate = $this->where (['id'=>$data['id']])->value ('sale_date');
        $redisSer = new RedisService();
        $redisSer->updateDateBetweenData ($saleDate,$saleDate);
        return $this->where(['id' => $data['id']])->update($data);
    }

    /**
     * 取该证书所有倒证记录
     * @param $id
     * @return \app\model\OrderEnterpriseExchange[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getWhereEnterIdData($id)
    {
        return $this->where(['enter_id' => $id])->select();
    }

    /**
     * 按时间排序 通过企业证书id 取最新一条倒证记录
     * @param $id
     * @return \app\model\OrderEnterpriseExchange|array|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getWhereEnterIdOrderByCreateData($id)
    {
        return $this->where(['enter_id' => $id])->order('create_date DESC')->find();
    }

    /**
     * 通过倒证id找证书id
     * @param $id
     * @return mixed
     */
    public function getWhereEnterIdOrderIdModel($id)
    {
        return $this->where(['id' => $id])->value('enter_id');
    }

    public function getIdDataModel($id)
    {
        $data = $this->where(['id' => $id])->findOrEmpty ();
        if (!$data->isEmpty ()){
            return $data->toArray ();
        }
        return [];
    }

    /**
     * 根据倒证id查询
     * @param $id
     * @return \app\model\OrderEnterpriseExchange|array|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getWhereIdOrderByCreateData($id)
    {
        $data = $this->where(['id' => $id])->order('create_date DESC')->findOrEmpty();
        if (!$data->isEmpty()) {
            return $data->toArray();
        }
        return null;
    }


    public function getWhereIdData($id)
    {
        $data = $this->where(['id' => $id])->find();
        if (!$data->isEmpty ()){
            return $data->toArray ();
        }
        return null;
    }
    public function getWhereIdDataSelectModel($id,$cer)
    {
        return $this->where(['id' => $id,'certificate_code'=>$cer])->select()->toArray ();
    }

    /**
     * 获取订单业绩归属人
     */
    public function getOrderPerformanceUidModel($id,$certificateCode)
    {
        return $this->where (['certificate_code'=>$certificateCode,'id'=>$id])->value ('performance_uid');
    }

    public function whereIdData($id)
    {
        return $this->whereIn('id',$id)->select()->toArray();
    }

    /**
     * 查询注册单位 | 聘用单位 | 出证单位 等于where信息
     * @param $where
     * @return array|null
     */
    public function getWhereInfoModel($where): ?array
    {
        $data = $this->where("unit_reg_title|employ_unit_title|out_unit", '=', $where)->findOrEmpty();
        if (!$data->isEmpty()) {
            return $data->toArray();
        }
        return null;
    }

    /**
     * 通过id范围查询倒证数据
     * @param $idArr
     * @return \app\model\OrderEnterpriseExchange[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getIdInDataModel($idArr, $uid)
    {
        return $this->with('certificateCode')->whereIn('id', $idArr)->whereOr(['notice_id' => $uid])->select();
    }

    /**
     * 根据证书编号查询企业倒证列表
     * @param $cer
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getCertificateCodeData($cer, $person_name,$employ_unit_title): array
    {
//        $db = $this->where('sfk_status',1);
//        if ($person_name){
//            $db->whereOr('out_unit',$person_name);
//        }
//        if ($employ_unit_title){
//            $db->whereOr('employ_unit_title',$employ_unit_title);
//        }
//        return $db->select ()->toArray ();
        if (empty($person_name) && !empty($employ_unit_title)){
            $data = $this->where(['employ_unit_title' => $employ_unit_title, 'sfk_status' => 1])->select()->toArray();
        } else if (empty($employ_unit_title) && !empty($person_name)) {
            $data = $this->where(['out_unit' => $person_name, 'sfk_status' => 1])->select()->toArray();
        } else if (!empty($employ_unit_title) && !empty($person_name)) {
            $data = $this->whereRaw('out_unit="' . $person_name . '" and sfk_status=1 OR employ_unit_title="' . $employ_unit_title . '" and sfk_status=1')->select()->toArray();
        }
        return $data;
    }


    /**
     * 获取证书应收款
     * @param $cer
     * @return array|null
     */
    public function getFinanceFieldFindModel($cer)
    {

//        $data =  OrderEnterpriseExchange::withJoin('certificates')
//            ->where (['order_enterprise_exchange.certificate_code'=>$cer])
//            ->findOrEmpty ();
        $data = $this->where(['certificate_code' => $cer])->findOrEmpty();

        if (!$data->isEmpty()) {

            return $data->toArray();
        }
        return null;
    }

    public function getIdCerFindModel($id,$cer)
    {
        $data = $this->where(['certificate_code' => $cer,'id'=>$id])->findOrEmpty();

        if (!$data->isEmpty()) {

            return $data->toArray();
        }
        return null;
    }

    /**
     * 修改订单状态为已退单
     * @param $cer
     * @param int $status
     * @return \app\model\OrderEnterpriseExchange
     */
    public function setStatusBack($cer, int $status = 3)
    {
        return $this->where(['certificate_code' => $cer])->update(['status' => $status]);
    }

    /**
     * 获取倒证出证价 收证价
     * @return array|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getSummaryModel($startDate, $endDate, $uidArr, $cerId = ''): ?array
    {
        //查询时间段内成交库的certificate_code
        //拼接whereIn条件
        $cerCode = Db::table('order_deal')->whereBetweenTime ('create_date',$startDate,$endDate)->column('certificate_code');

        $performance = 0;
        if (empty($cerId)) {

//            $data = $this->whereIn('performance_uid', $uid)->whereRaW('status=1 OR status=2')->whereBetweenTime('create_date', $startDate, $endDate)->field('sum(performance) as performance_sum')->find();
            $data = $this->whereRaW('status=1 OR status=2 OR status=3 OR status = 4 OR status = 5')->whereIn ('certificate_code',$cerCode)->field('id,performance,performance_uid')->select ()->toArray ();

            //判断业绩归属人是否存在uidArr
            if (!is_array ($uidArr)){
                $uidArr = explode (',',$uidArr);
            }

            foreach ($data as $datum) {
                if (empty($datum['performance_uid'])){
                    continue;
                }
                $datumPidArr = explode (',',$datum['performance_uid']);

                $datumPidCount = count($datumPidArr);
                foreach ($datumPidArr as $item) {
                    if (in_array ($item, $uidArr)){
                        if (!$datum['performance']) $datum['performance']=0;
                        $performance += round ($datum['performance']/$datumPidCount,2);
                    }
                }
            }
        }else{
            $data = $this->whereIn('certificate_leixing', $cerId)->whereRaW('status=1 OR status=2 OR status=3 OR status = 4 OR status = 5')->whereIn ('certificate_code',$cerCode)->field('id,performance,performance_uid')->select ()->toArray ();
            //判断业绩归属人是否存在uidArr
            if (!is_array ($uidArr)){
                $uidArr = explode (',',$uidArr);
            }

            foreach ($data as $datum) {
                $datumPidArr = explode (',',$datum['performance_uid']);
                $datumPidCount = count($datumPidArr);
                foreach ($datumPidArr as $item) {
                    if (in_array ($item, $uidArr)){
                        if (!$datum['performance']) $datum['performance']=0;
                        $performance += round ($datum['performance']/$datumPidCount,2);
                    }
                }
            }
        }
        return ['performance_sum'=>$performance];
    }

    /**
     * 二类业务占比
     * @param $startDate
     * @param $endDate
     * @param $uidArr
     * @param string $cerId
     * @return int[]|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getErleiZhanBiModel($startDate, $endDate, $uidArr, string $cerId = ''): ?array
    {
        //查询时间段内成交库的certificate_code
        //拼接whereIn条件
//        $cerCode = Db::table('order_deal')->whereBetweenTime ('create_date',$startDate,$endDate)->column('certificate_code');

        $performance = 0;
        if (empty($cerId)) {

//            $data = $this->whereIn('performance_uid', $uid)->whereRaW('status=1 OR status=2')->whereBetweenTime('create_date', $startDate, $endDate)->field('sum(performance) as performance_sum')->find();
            $data = $this->whereRaW('status=1 OR status=2 status = 5')->whereBetweenTime ('create_date',$startDate,$endDate)->select ()->toArray ();

            //判断业绩归属人是否存在uidArr
            if (!is_array ($uidArr)){
                $uidArr = explode (',',$uidArr);
            }

            foreach ($data as $datum) {
                if (empty($datum['performance_uid'])){
                    continue;
                }
                $datumPidArr = explode (',',$datum['performance_uid']);

                $datumPidCount = count($datumPidArr);
                foreach ($datumPidArr as $item) {
                    if (in_array ($item, $uidArr)){
                        if (!$datum['performance']){
                            continue;
                        }
                        $performance += round ($datum['performance']/$datumPidCount,2);
                    }
                }
            }
        }else{
            $data = $this->whereIn('certificate_leixing', $cerId)->whereRaW('status=1 OR status=2 OR status = 5')->whereBetweenTime ('create_date',$startDate,$endDate)->select ()->toArray ();
            //判断业绩归属人是否存在uidArr

            if (!is_array ($uidArr)){
                $uidArr = explode (',',$uidArr);
            }

            foreach ($data as $datum) {
                $datumPidArr = explode (',',$datum['performance_uid']);
                $datumPidCount = count($datumPidArr);
                foreach ($datumPidArr as $item) {
                    if (in_array ($item, $uidArr)){
                        if (!$datum['performance']){
                            continue;
                        }
                        $performance += round ($datum['performance']/$datumPidCount,2);
                    }
                }
            }
        }
        return ['performance_sum'=>$performance];
    }

    /**
     * 成交总数量
     * @return int
     * @throws \think\db\exception\DbException
     */
    public function getOrderNumModel($startDate, $endDate, $uidArr): int
    {
        //查询成交时间
        $dealModel = new OrderDeal();
        $count = 0;
        $data = $this->whereRaw('status = 1 OR status = 2 OR status = 5')->select();
        //判断业绩归属人是否存在uidArr
        if (!is_array ($uidArr)){
            $uidArr = explode (',',$uidArr);
        }

        foreach ($data as $datum) {
            if (empty($datum['performance_uid'])){
                continue;
            }
            $datumPidArr = explode (',',$datum['performance_uid']);

            $datumPidCount = count($datumPidArr);
            foreach ($datumPidArr as $item) {
                if (!in_array ($item, $uidArr)){
                    continue;
                }
                //查看成交时间
                $dealData = $dealModel->getOrderCompanyIdFindModel($datum['id'],$datum['certificate_code']);
                if ($dealData){
                    if (strtotime ($dealData['create_date']) > strtotime ($startDate) && strtotime ($dealData['create_date']) < strtotime ($endDate)){
                        $count++;
                        break;
                    }
                }
            }

        }
        return $count;
    }

    /**
     * 统计业务总数
     * @param $id
     * @return int
     * @throws \think\db\exception\DbException
     */
    public function getBusinessIdCountModel($id): int
    {
        return $this->where(['business_id' => $id, 'status' => 2])->count();
    }

    /**
     * Ⅱ类业绩排行榜（滚动）
     * @param $startDate
     * @param $endDate
     * @param $cerArr
     * @return mixed
     */
    public function getPhbModel($startDate, $endDate, $idArr, $cerArr)
    {
        $orderDealChargebackModel = new OrderDealChargeback();

        $idData = $this->whereBetweenTime('sale_date', $startDate, $endDate)
            ->whereIn('certificate_leixing', $cerArr)
            ->whereRaw('status=1 OR status=2 OR status=3 OR status = 4 OR status = 5')
            ->field('id,performance_uid,performance,certificate_leixing,certificate_code')
            ->select()->toArray();

        $data = [];

        $tdData = $orderDealChargebackModel->getBetDateTypeModel($startDate,$endDate);

        /**
         * 以每个人去统计
         */
        if (!is_array ($idArr)){
            $idArr = explode (',',$idArr);
        }
        foreach ($idArr as $id) {
            //统计退单
            $tdPrice = 0;
            $yj = 0;
//            $rUidArr = array_column ($data,'performance_uid');
            if ($tdData){
                foreach ($tdData as $tdDatum) {
                    //查询订单信息
                    $daOrder = $this->where (['id'=>$tdDatum['order_company_id'],'certificate_code'=>$tdDatum['certificate_code']])->whereIn('certificate_leixing', $cerArr)->find ();
                    if ($daOrder){
                        //查看业绩归属人有几人
                        $performanceArr = explode (',', $daOrder['performance_uid']);
                        foreach ($performanceArr as $performanceArrItem) {
                            if ($performanceArrItem == $id){
                                $tdPrice += $tdDatum['performance']/count($performanceArr);
                            }
                        }
                    }
                }
            }
            //统计订单
            foreach ($idData as $idDatum) {
                $idArrs = explode (',',$idDatum['performance_uid']);
                $idCount = count($idArrs);
                foreach ($idArrs as $items) {
                    if ($items == $id){
                        $yj += $idDatum['performance']/$idCount;
                    }
                }
            }

            $data[] = [
                'performance_uid'=>$id,
                'all_out_price'=>$yj + $tdPrice
            ];
//            if (in_array ($id,$rUidArr)){
//                $data[array_search ($id,$rUidArr)]['all_out_price'] += $yj +$tdPrice;
//            }else{
//                $data[] = [
//                    'performance_uid'=>$id,
//                    'all_out_price'=>$yj + $tdPrice
//                ];
//            }
        }
        return $data;
    }

    /**
     * 通过证书id查询补全资料
     * @param $id
     * @return array|null
     */
    public function getExcelInfoModel($id): ?array
    {
        $data = $this->where(['id' => $id])
            ->field('person_name,out_price as sale_price,employ_unit_title as employ_unit,unit_reg_title as reg_unit,out_unit,get_price')
            ->findOrEmpty();
        if (!$data->isEmpty()) {
            return $data->toArray();
        }
        return null;
    }

    /**
     * Ⅰ类业绩统计 + 排行
     */
    public function getYileiWorkCount($startDate, $endDate, $cer, $uid)
    {

        return $this->whereBetweenTime('create_date', $startDate, $endDate)
            ->whereRaw('(status = 1 OR status =2 OR status = 5) AND certificate_zhuanye =' . $cer . ' AND get_uid in ('.$uid.')')
            ->field('get_uid,sum(out_price)-sum(get_price) as all_out_price')
            ->select()->toArray();
    }

    /**
     * 根据id查询单条信息
     * @param $id
     * @return array|null
     */
    public function getWhereCerDataModel($cer)
    {
        $data = $this->where(['certificate_code' => $cer])->findOrEmpty();

        if (!$data->isEmpty()) {
            return $data->toArray();
        }
        return null;
    }

    /**
     * 根据成熟编号查询订单field
     */
    public function getWhereCerFieldDataModel($cer,$field): ?array
    {
        $data = $this->where(['certificate_code' => $cer])->field($field)->findOrEmpty();

        if (!$data->isEmpty ()){
            return $data->toArray ();
        }
        return null;

    }

    /**
     * 完成订单操作
     * @param $id
     * @return \app\model\OrderEnterpriseExchange
     */
    public function completeOperateModel($id)
    {
        return $this->where(['id' => $id])->update(['status' => 1]);
    }

    /**
     * 证书注册完成
     * @param $id
     * @return \app\model\OrderEnterpriseExchange
     */
    public function certificateRegModel($id)
    {
        return $this->where(['id' => $id])->update(['status' => 2]);
    }

    /**
     * 获取企业倒证应收款
     * @param $cer
     * @return mixed
     */
    public function getCerGetPriceModel($cer)
    {
        return $this->where(['certificate_code' => $cer])->value('out_price');
    }

    /**
     * 获取应付款
     * @param $cer
     * @return mixed
     */
    public function getCerOutPriceModel($cer)
    {
        return $this->where(['certificate_code' => $cer])->value('get_price');
    }

    /**
     * 业绩总表修改业绩
     * @param $param
     * @return \app\model\OrderEnterpriseExchange
     */
    public function editIdPerformanceModel($param)
    {
        return $this->where(['certificate_code' => $param['certificate_code']])->update(['performance' => $param['performance'], 'ad_performance' => 1]);
    }

    /**
     * 查询聘用单位订单量
     * @param $title
     * @return int
     * @throws \think\db\exception\DbException
     */
    public function getPinYongUnitOrderNumModel($title): int
    {
        return $this->where(['employ_unit_title' => $title])->count();
    }

    /**
     * 查询当前账号提交聘用单位订单量
     * @param $title
     * @param $uid
     * @return int
     * @throws \think\db\exception\DbException
     */
    public function getUidPinYongUnitOrderNumModel($title,$uid): int
    {
        return $this->where (['employ_unit_title'=>$title,'get_uid'=>$uid])->count();
    }

    /**
     * 查询聘用单位订单量
     * @param $title
     * @return int
     * @throws \think\db\exception\DbException
     */
    public function getChuZhengUnitOrderNumModel($title): int
    {
        return $this->where (['out_unit'=>$title])->count();
    }

    /**
     * 查询当前账号提交聘用单位订单量
     * @param $title
     * @param $uid
     * @return int
     * @throws \think\db\exception\DbException
     */
    public function getUidChuZhengUnitOrderNumModel($title,$uid): int
    {
        return $this->where (['out_unit'=>$title,'get_uid'=>$uid])->count();
    }

    /**
     * 查询聘用单位订单量
     * @param $title
     * @return int
     * @throws \think\db\exception\DbException
     */
    public function getRegUnitOrderNumModel($title): int
    {
        return $this->where (['unit_reg_title'=>$title])->count();
    }

    /**
     * 查询当前账号提交聘用单位订单量
     * @param $title
     * @param $uid
     * @return int
     * @throws \think\db\exception\DbException
     */
    public function getUidRegUnitOrderNumModel($title,$uid): int
    {
        return $this->where (['unit_reg_title'=>$title,'get_uid'=>$uid])->count();
    }

    /**************************************
     * 公示栏条件查询加分页
     * @param $where
     * @param $page
     * @return \app\model\OrderEnterpriseCertificateRegister[]|array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getPublicityListModel($where,$page,$sort)
    {
        return $this->where ($where)->page ($page,stateData::$_page)->order($sort)->select ()->toArray ();
    }

    public function getPublicityAllModel($where)
    {
        return $this->where ($where)->select ()->toArray ();
    }

    public function getPublicityCountModel($where)
    {
        return $this->where ($where)->count();
    }

    /**
     * 通过身份证查询关联订单
     * @param $person_id_card
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getIdCardOrderInfoModel($person_id_card)
    {
        return $this->where (['id_card'=>$person_id_card])->select ()->toArray ();
    }


    /**
     * 完成订单收付款
     * @param $id
     * @return
     */
    public function completeOrderSFKModel($id)
    {
        return $this->where(['id' => $id])->update(['sfk_status' => 2,'sfk_wc_date'=>date('Y-m-d H:i:s')]);
    }

    /**
     * 完成后点击返回按钮 状态改为未完成 完成时间改为空
     * @param $id
     * @return OrderEnterpriseExchange
     */
    public function backCompleteOrderSFKModel($id)
    {
        return $this->where(['id' => $id])->update(['sfk_status' => 1, 'sfk_wc_date' => null]);
    }

    public function delIdModel($id)
    {
//        return $this->where ('id',$id)->delete();
        return self::destroy($id);
    }

    public function getExcelModel($id)
    {
        return $this->whereIn('id',$id)->order('create_date DESC')->select()->toArray();
    }



    /**
     * 查询通知人为当前id的信息id集
     * @param $id
     * @return array
     */
    public function getNoticeIdDataModel($id)
    {
        return $this->where (['notice_id'=>$id])->column ('id');
    }
    public function editNoticeIdDataModel($idArr,$id)
    {
        return $this->whereIn ('id',$idArr)->update (['notice_id'=>$id]);
    }

    /**
     * 查询收证人员为当前id的信息id集
     * @param $id
     * @return array
     */
    public function getGetUidDataModel($id)
    {
        return $this->where (['get_uid'=>$id])->column ('id');
    }
    public function editGetUidDataModel($idArr,$id,$org)
    {
        return $this->whereIn ('id',$idArr)->update (['get_uid'=>$id,'get_org'=>$org]);
    }

    /**
     * 查询发起人为当前id的信息id集
     * @param $id
     * @return array
     */
    public function getSubmitUidDataModel($id)
    {
        return $this->where (['submit_id'=>$id])->column ('id');
    }
    public function editSubmitUidDataModel($idArr,$id)
    {
        return $this->whereIn ('id',$idArr)->update (['submit_id'=>$id]);
    }

    /**
     * 查询出证人为当前id的信息id集
     * @param $id
     * @return array
     */
    public function getOutUidDataModel($id)
    {
        return $this->where (['out_uid'=>$id])->column ('id');
    }
    public function editOutUidDataModel($idArr,$id,$org)
    {
        return $this->whereIn ('id',$idArr)->update (['out_uid'=>$id,'out_org'=>$org]);
    }

    public function getIdStatusModel($id)
    {
        return $this->where (['id'=>$id])->value ('status');
    }

    /**
     * 证书注销操作
     * @param $id
     * @param int $status
     */
    public function setLogOffModel($id,$cer, int $status=4)
    {
        return $this->where (['certificate_code'=>$cer,'id'=>$id])->update (['status'=>$status]);
    }

    /**
     * 获取订单idcard
     * @param $order_company_id
     * @param $certificate_code
     * @return mixed
     */
    public function getCerIdcardFindModel($order_company_id, $certificate_code)
    {
        return $this->where (['id'=>$order_company_id,'certificate_code'=>$certificate_code])->value ('id_card');
    }

    /**
     * 订单续签
     * @param $id
     * @param $certificate_code
     * @param int $status
     * @return \app\model\OrderEnterpriseExchange
     */
    public function setXuQianModel($id, $certificate_code, int $status=5)
    {
        return $this->where (['certificate_code'=>$certificate_code,'id'=>$id])->update (['status'=>$status]);
    }

    /**
     * 业绩统计-证书注册
     * @param $uid
     * @param $status
     * @param $startDate
     * @param $endDate
     * @return int[]
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
//    public function getUidCerDateDataModel($uid,$status,$startDate,$endDate)
//    {
//        $orderDealModel = new OrderDeal();
//
//        $orderChargebackModel = new OrderDealChargeback();
//
////        $data = $this->whereRaw ('out_uid='.$uid.' OR get_uid='.$uid)
////            ->whereBetweenTime ('create_date',$startDate,$endDate)
////            ->field('id,certificate_code,performance,performance_uid')
////            ->select ()->toArray ();
//
//        $data = $orderDealModel->getDateCerIdDataModel($startDate,$endDate,$status);
//
//        $container = [
//            'order_num'=>0,
//            'order_price'=>0
//        ];
//        if ($data) {
//            foreach ($data as $item) {
//                //查询订单成交状态是新出 续出 续签
////                if ($item['status'] != $status){
////                    continue;
////                }
////                if (!$orderDealModel->getCerStatusEmptyModel($item,$status)){
////                    continue;
////                }
//                $findComData = $this->whereRaw ('out_uid='.$uid.' OR get_uid='.$uid)
//                        ->where (['certificate_code'=>$item])
//                        ->field('id,certificate_code,performance,performance_uid')
//                        ->find ();
//
//                if (!$findComData){
//                    continue;
//                }
//
//                //满足条件 计算业绩、单量
//                $dUidArr = explode (',',$findComData['performance_uid']);
//                if (in_array ($uid,$dUidArr)){
//                    $container['order_num']++;
//                }
//
//                foreach ($dUidArr as $id) {
//                    if ($uid == $id){
//                        $container['order_price'] += $findComData['performance']/count ($dUidArr);
//                    }
//                }
//
//                //查询退单信息
//                $backDataPerformance = $orderChargebackModel->getOrderBackPerformance($findComData['id'],$findComData['certificate_code'],$startDate,$endDate);
//                if (!empty($backDataPerformance)){
//                    //今天成交订单  今日订单+1 业绩+500
//                    //第二天退单 第一天不变 第二日订单-1 业绩-500
//                    if (in_array ($uid,$dUidArr)){
//                        $container['order_num']--;
//                    }
//                    foreach ($dUidArr as $id) {
//                        if ($uid == $id){
//                            $container['order_price'] += $backDataPerformance/count ($dUidArr);
//                        }
//                    }
//
//                }
//            }
//        }
//        return $container;
//    }

    public function getUidCerDateDataModel($uid,$status,$startDate,$endDate)
    {
        $orderDealModel = new OrderDeal();

        $orderChargebackModel = new OrderDealChargeback();

//        $data = $this->whereRaw ('out_uid='.$uid.' OR get_uid='.$uid)
//            ->whereBetweenTime ('create_date',$startDate,$endDate)
//            ->field('id,certificate_code,performance,performance_uid')
//            ->select ()->toArray ();

//        $data = $orderDealModel->getDateCerIdDataModel($startDate,$endDate);

        $container = [
            'new_order_num'=>0, //新出
            'new_order_price'=>0,
            'xq_order_num'=>0, //续签
            'xq_order_price'=>0,
            'xc_order_num'=>0, //续出
            'xc_order_price'=>0
        ];

        $data = Db::table('order_enterprise_exchange')->alias ('c')
            ->join ('order_deal d','c.certificate_code=d.certificate_code')
            ->whereBetweenTime ('d.create_date',$startDate,$endDate)
            ->field('d.status,c.id,c.certificate_code,c.performance,c.performance_uid')->select();
        foreach ($data as $item) {
            //满足条件 计算业绩、单量
            $dUidArr = explode (',',$item['performance_uid']);
            if (in_array ($uid,$dUidArr)){
                if($item['status'] == 1){ //新出
                    $container['new_order_num']++;
                }else if($item['status'] == 2){
                    $container['xq_order_num']++;
                }else if($item['status'] == 3){
                    $container['xc_order_num']++;
                }
            }

            foreach ($dUidArr as $id) {
                if ($uid == $id){
                    if($item['status'] == 1){ //新出
                        $container['new_order_price'] += $item['performance']/count ($dUidArr);
                    }else if($item['status'] == 2){
                        $container['xq_order_price'] += $item['performance']/count ($dUidArr);
                    }else if($item['status'] == 3){
                        $container['xc_order_price'] += $item['performance']/count ($dUidArr);
                    }
                }
            }

//                查询退单信息
            $backDataPerformance = $orderChargebackModel->getOrderBackPerformance($item['id'],$item['certificate_code'],$startDate,$endDate);
            if (!empty($backDataPerformance)){
                //今天成交订单  今日订单+1 业绩+500
                //第二天退单 第一天不变 第二日订单-1 业绩-500
                if (in_array ($uid,$dUidArr)){
                    if($item['status'] == 1){ //新出
                        $container['new_order_num']--;
                    }else if($item['status'] == 2){
                        $container['xq_order_num']--;
                    }else if($item['status'] == 3){
                        $container['xc_order_num']--;
                    }
                }
                foreach ($dUidArr as $id) {
                    if ($uid == $id){
                        if($item['status'] == 1){ //新出
                            $container['new_order_price'] += $backDataPerformance/count ($dUidArr);
                        }else if($item['status'] == 2){
                            $container['xq_order_price'] += $backDataPerformance/count ($dUidArr);
                        }else if($item['status'] == 3){
                            $container['xc_order_price'] += $backDataPerformance/count ($dUidArr);
                        }
                    }
                }

            }
        }
//        if ($data) {
//            foreach ($data as $item) {
//                //查询订单成交状态是新出 续出 续签
////                if ($item['status'] != $status){
////                    continue;
////                }
////                if (!$orderDealModel->getCerStatusEmptyModel($item,$status)){
////                    continue;
////                }
//                $findComData = $this->where (['certificate_code'=>$item['certificate_code']])
//                    ->field('id,certificate_code,performance,performance_uid')
////                    ->fetchSql(true)
//                    ->find ();
//
//                if (!$findComData){
//                    continue;
//                }
////    echo $this->getLastSql();die;
//                //满足条件 计算业绩、单量
//                $dUidArr = explode (',',$findComData['performance_uid']);
//                if (in_array ($uid,$dUidArr)){
//                    if($item['status'] == 1){ //新出
//                        $container['new_order_num']++;
//                    }else if($item['status'] == 2){
//                        $container['xq_order_num']++;
//                    }else if($item['status'] == 3){
//                        $container['xc_order_num']++;
//                    }
//                }
//
//                foreach ($dUidArr as $id) {
//                    if ($uid == $id){
//                        if($item['status'] == 1){ //新出
//                            $container['new_order_price'] += $findComData['performance']/count ($dUidArr);
//                        }else if($item['status'] == 2){
//                            $container['xq_order_price'] += $findComData['performance']/count ($dUidArr);
//                        }else if($item['status'] == 3){
//                            $container['xc_order_price'] += $findComData['performance']/count ($dUidArr);
//                        }
//                    }
//                }
//
////                查询退单信息
//                $backDataPerformance = $orderChargebackModel->getOrderBackPerformance($findComData['id'],$findComData['certificate_code'],$startDate,$endDate);
//                if (!empty($backDataPerformance)){
//                    //今天成交订单  今日订单+1 业绩+500
//                    //第二天退单 第一天不变 第二日订单-1 业绩-500
//                    if (in_array ($uid,$dUidArr)){
//                        if($item['status'] == 1){ //新出
//                            $container['new_order_num']--;
//                        }else if($item['status'] == 2){
//                            $container['xq_order_num']--;
//                        }else if($item['status'] == 3){
//                            $container['xc_order_num']--;
//                        }
//                    }
//                    foreach ($dUidArr as $id) {
//                        if ($uid == $id){
//                            if($item['status'] == 1){ //新出
//                                $container['new_order_price'] += $backDataPerformance/count ($dUidArr);
//                            }else if($item['status'] == 2){
//                                $container['xq_order_price'] += $backDataPerformance/count ($dUidArr);
//                            }else if($item['status'] == 3){
//                                $container['xc_order_price'] += $backDataPerformance/count ($dUidArr);
//                            }
//                        }
//                    }
//
//                }
//            }
//        }
        return $container;
    }

    /**
     * 业绩统计-证书注册优化
     * @param $uid
     * @param $status
     * @param $startDate
     * @param $endDate
     * @return int[]
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getUidCerDateDataYhModel($uid,$cer,$startDate,$endDate)
    {
        $orderChargebackModel = new OrderDealChargeback();
        $container = [
            'order_num'=>0,
            'order_price'=>0
        ];

        $findComData = $this->where (['certificate_code'=>$cer])
            ->field('id,certificate_code,performance,performance_uid')
            ->find ();

        if ($findComData){
            //满足条件 计算业绩、单量
            $dUidArr = explode (',',$findComData['performance_uid']);
            if (in_array ($uid,$dUidArr)){
                $container['order_num']++;
            }

            foreach ($dUidArr as $id) {
                if ($uid == $id){
                    $container['order_price'] += $findComData['performance']/count ($dUidArr);
                }
            }

            //查询退单信息
            $backDataPerformance = $orderChargebackModel->getOrderBackPerformance($findComData['id'],$findComData['certificate_code'],$startDate,$endDate);
            if (!empty($backDataPerformance)){
                //今天成交订单  今日订单+1 业绩+500
                //第二天退单 第一天不变 第二日订单-1 业绩-500
                if (in_array ($uid,$dUidArr)){
                    $container['order_num']--;
                }
                foreach ($dUidArr as $id) {
                    if ($uid == $id){
                        $container['order_price'] += $backDataPerformance/count ($dUidArr);
                    }
                }

            }
        }
        return $container;
    }

    public function getWhereModel(string $where, $idArr, string $startDate, string $endDate)
    {
        $orderDealModel = new OrderDeal();

        $orderChargebackModel = new OrderDealChargeback();

        $container = [
            'order_num'=>0,
            'order_price'=>0
        ];

        $idStr = implode (',', $idArr);
        $data = $this
            ->whereRaw ($where)
            ->whereRaw ('out_uid IN ('.$idStr.') OR get_uid IN('.$idStr.')')
            ->whereBetweenTime ('create_date',$startDate,$endDate)
            ->select ()
            ->toArray ();
        if (!empty($data)){


            foreach ($data as $datum) {
                //查询成交状态以及成交时间内数据
                $dealData = $orderDealModel->getCerComIdDateDataModel($datum['id'],$datum['certificate_code'],'',$startDate,$endDate);
                if (!empty($dealData)){
                    //满足条件 计算业绩、单量
                    $dUidArr = explode (',',$datum['performance_uid']);
                    foreach ($dUidArr as $item) {
                        if (in_array ($item,$idArr)){
                            $container['order_num']++;
                            break;
                        }
                    }
                    foreach ($dUidArr as $item) {
                        if (in_array ($item,$idArr)){
                            $container['order_price'] += $datum['performance']/count ($dUidArr);
                        }
                    }


                    //查询退单信息
                    $backData = $orderChargebackModel->getCidCerTypeDataModel($datum['id'],$datum['certificate_code'],$startDate,$endDate);
                    if (!empty($backData)){
                        foreach ($dUidArr as $items) {
                            if (in_array ($items,$idArr)){
                                $container['order_num']--;
                                break;
                            }
                        }
                        foreach ($dUidArr as $items) {
                            if (in_array ($items,$idArr)){
                                $container['order_price'] += $backData['performance']/count ($dUidArr);
                            }
                        }
                    }
                }
            }
        }

        return $container;
    }

    public function getEnterPriseDataModel(array $cerArr, string $startDate, string $endDate)
    {
        return $this->whereIn ('certificate_code',$cerArr)
//            ->fetchSql(true)
            ->column ('id,performance,performance_uid,certificate_code');
//            ->field('id,performance,performance_uid,certificate_code')
//            ->select ()->toArray ();
    }

    /**
     * 业绩总表添加备注
     * @param $param
     * @return \app\model\OrderEnterpriseExchange
     */
    public function editIdLabelModel($param)
    {
        return $this->where(['id'=>$param['id'],'certificate_code'=>$param['certificate_code']])->update (['label'=>$param['label']]);
    }

    /**
     * 查询今日订单个数
     * @return int
     * @throws \think\db\exception\DbException
     */
    public function getToDayCountFindModel():int
    {
        return  $this->whereDay('create_date')->count ();
    }


    /**
     * 更改倒证表生产信息状态
     * @param $id
     * @param $status
     * @return OrderEnterpriseExchange
     */
    public function editInfoGenerateStatus($id, $status,$operate)
    {
        return $this->where(['id' => $id])->update(['info_generate_status' => $status,'info_generate_operate' => $operate]);
    }
}